package com.example.lanouhn.firstapp.activity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lanouhn.firstapp.R;
import com.example.lanouhn.firstapp.activity.model.Classify;
import com.example.lanouhn.firstapp.activity.model.NappyPants;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * 分类下的三级  item  的专用解析的适配器
 * Created by lanouhn on 16/7/19.
 */
public class NappyPantsAdapter extends BaseAdapter {
    //定义数组及上下文
    private List<NappyPants> list;
    private Context context;

    public NappyPantsAdapter(List<NappyPants> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder holder = null;
        if (view == null) {
            //View view = View.inflate(context, R.layout.notes_item,null);
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_nappy_pants, null);

            holder.goods_name = (TextView) view.findViewById(R.id.goods_name);
            holder.goods_image_url = (ImageView) view.findViewById(R.id.goods_image_url);
            holder.goods_price = (TextView) view.findViewById(R.id.goods_price);
            holder.goods_salenum = (TextView) view.findViewById(R.id.goods_salenum);

            view.setTag(holder);
        }else {
            holder = (ViewHolder)view.getTag();
        }
        NappyPants nappyPants = list.get(i);
        holder.goods_name.setText( nappyPants.getGoods_name());
        //导入Picasso包   用来快速获取网络图片
        Picasso.with(context).load(nappyPants.getGoods_image_url()).into(holder.goods_image_url);
        holder.goods_price.setText(nappyPants.getGoods_price());
        holder.goods_salenum.setText(nappyPants.getGoods_salenum());


        return view;
    }
        class ViewHolder {
            private TextView goods_name;
            private ImageView goods_image_url;
            private TextView goods_price;
            private TextView goods_salenum;

        }
}




